package com.help.knowhelps.ui;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;

import com.help.knowhelps.R;
import com.help.knowhelps.R.string;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity{

	EditText et_name,et_pwd;
	View bt_login,bt_findback,bt_signin;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.login_activity);
		initComponent();
	}
	private void initComponent()
	{
		UiUtils.InitActionBar(this, "", UiUtils.ACTIONBAR_BUTTON_DEFAULT, 
				UiUtils.ACTIONBAR_BUTTON_DISAPPEAR ,clicklistener);
		findViewById(R.id.actionbar_background).setBackgroundColor(Color.TRANSPARENT);
		et_name = (EditText) findViewById(R.id.login_editText_name);
		et_pwd = (EditText) findViewById(R.id.login_editText_pwd);
		bt_login = findViewById(R.id.login_TextView_login);
		bt_signin = findViewById(R.id.login_TextView_signin);
		bt_findback = findViewById(R.id.login_TextView_findback);
		bt_login.setOnClickListener(clicklistener);
		bt_signin.setOnClickListener(clicklistener);
		bt_findback.setOnClickListener(clicklistener);
	}
	private boolean CheckOutUser(String name,String pwd)
	{
		//do...    账户密码,请求服务器,卡ui,超时处理.
		return false;
	}
	Intent it_user;
	private OnClickListener clicklistener = new OnClickListener() {
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.actionbar_imageView_left:
				finish();
				break;
			case R.id.login_TextView_login:
				String name = et_name.getText().toString();
				String pwd = et_pwd.getText().toString();
				if(null == name||name.equals("")||null == pwd||pwd.equals(""))
				{
					Toast.makeText(LoginActivity.this, "账号或密码输入有误,请重新输入!", Toast.LENGTH_SHORT).show();
				}else	if(CheckOutUser(name,pwd))
				{
					//do...  islogin = true;更新至全局
					finish();
				}else
				{
					Toast.makeText(LoginActivity.this, "登陆失败,请重新尝试", Toast.LENGTH_SHORT).show();
				}
				break;
			case R.id.login_TextView_findback:
				it_user = new Intent(LoginActivity.this,RegisterActivity.class);
				it_user.putExtra("FindBackCode", true);
			case R.id.login_TextView_signin:
				if(it_user ==null)
					it_user = new Intent(LoginActivity.this,RegisterActivity.class);
				startActivity(it_user);
				finish();
				break;
			default:
				break;
			}
		}
	};
}